package com.xt.service.impl;

import com.xt.bean.KnowledgePoint;
import com.xt.dao.KnowledgePointRepository;
import com.xt.service.KnowledgePointService;
import com.xt.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * Created by XT on 2018/5/4.
 */
@Service
public class KnowledgePointServiceImpl implements KnowledgePointService {

    @Autowired
    private KnowledgePointRepository knr;

    @Override
    public void saveOrUpdateOne(KnowledgePoint k){

        if (StringUtils.isEmpty(k.getId())){
            //新增
            k.setCreateDate(new Date());
        }

        k.setUpdateDate(new Date());
        knr.save(k);
    }

    @Override
    public void deleteOne(String id){
        //删除关联关系

        knr.delete(id);
    }

    @Override
    public KnowledgePoint getById(String id){
        return knr.findOne(id);
    }

    @Override
    public Page<KnowledgePoint> getKnowledgePointListByPage(int count, int pageNo, String sortDirection, String... sortField) {
        Page<KnowledgePoint> knowledgePointsPage = knr.findAll(PageUtil.getPageable(count,pageNo,sortDirection,sortField));
        return knowledgePointsPage;
    }



}

